﻿using System;
using Gadgeteer.Modules.GHIElectronics;
using Gadgeteer.Interfaces.Graphics;

namespace Gadgeteer.Interfaces.GHI.CharacterDisplay
{
    internal class Display_HD44780Wrapper : ICharacterDisplay
    {
        private readonly Display_HD44780 display;

        internal Display_HD44780Wrapper(Display_HD44780 display)
        {
            if (display == null) throw new ArgumentNullException("display");

            this.display = display;
        }

        public void Clear()
        {
            display.Clear();
        }

        public void CursorHome()
        {
            display.CursorHome();
        }

        public void PrintString(string text)
        {
            display.PrintString(text);
        }

        public void Putc(byte c)
        {
            Putc(c);
        }

        public void SetBacklight(BackLightMode mode)
        {
            switch (mode)
            {
                case BackLightMode.On:
                    display.SetBacklight(true);
                    break;
                case BackLightMode.Off:
                    display.SetBacklight(false);
                    break;
                case BackLightMode.None:
                default:
                    throw new InvalidOperationException("Unknown how to use display mode: " + mode);
            }
        }

        public void SetCursor(byte row, byte col)
        {
            display.SetCursor(row, col);
        }
    }
}
